import api from '../network/apis/api';
export default {
    namespaced: true,
    state: {
        //管理员订单列表
        PageData: {
            pageSize: 4, // 每页显示条数
            currentPage: 1, // 当前页
            totalPages: 1, // 总页数
            total: 0, // 总条数
            data: []
        },
        //管理员退款列表
        refoundList: {
            pageSize: 2, // 每页显示条数
            currentPage: 1, // 当前页
            totalPages: 1, // 总页数
            total: 0, // 总条数
            data: []
        },
        //销售员订单列表数据
        myOrderPageData: {
            pageSize: 3, // 每页显示条数
            currentPage: 1, // 当前页
            totalPages: 1, // 总页数
            total: 0, // 总条数
            data: []
        }
    },
    mutations: {
        setPageData(state, val) {
            state.PageData = val;
        },
        setRefoundList(state, val) {
            state.refoundList = val;
        },
        //设置销售员订单列表
        setMyOrderData(state, val) {
            state.myOrderPageData = val;
        }
    },
    actions: {
        //获得订单
        async getOrders(context) {
            const {
                data
            } = await api.orders.getAllOrders({
                currentPage: context.state.PageData.currentPage,
                pageSize: context.state.PageData.pageSize,
            });
            console.log(data.data);
            if (data.status) {
                context.commit('setPageData', data.data);
            }
        },

        //获得申请退款的订单
        async getList(context) {
            const {
                data
            } = await api.orders.getRefoundList({
                currentPage: context.state.refoundList.currentPage,
                pageSize: context.state.refoundList.pageSize,
            });
            if (data.status) {
                context.commit('setRefoundList', data.data);
            }

        },

        //获得销售员的订单
        async getSalesmanOrder(context, value) {
            const {
                data
            } = await api.orders.getSalesmanOrder({
                _id: value._id,
                type: value.type,
                currentPage: context.state.myOrderPageData.currentPage,
                pageSize: context.state.myOrderPageData.pageSize,
            });
            if (data.status) {
                context.commit("setMyOrderData", data.data);
                return data.data;
            }
        }

    }
}